<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!--  gb2312 -->
<title>Test</title>

<script type="text/javascript" language="javascript"> 
		
	function test(asy)
	{
		var type ,cmd ;
		var Mny,OldDate,OldReference,TraceID;
		
		var objSelect = document.getElementById("TranType");
		var index = objSelect.selectedIndex; 
		var text = objSelect.options[index].text; 
		var value = objSelect.options[index].value;
		type = value;

		Mny = document.getElementById('txtMny').value;
		//alert('mny="'+Mny+'"');
		OldDate = document.getElementById('txtOldDate').value;
		//alert('OldDate="'+OldDate+'"');
		OldReference = document.getElementById('txtOldRefSys').value;
		//alert('OldReference="'+OldReference+'"');
		TraceID = document.getElementById('txtTraceID').value;
		//alert('TraceID="'+TraceID+'"');

		var iRet,flag;
		var strInput = "";
		flag = type;
		//alert(flag);
			
		//(收银机号8,操作员号8,
		//交易类型2,金额12,原交易日期8,原参考号12,流水号6,
		//原批次号6,原授权码6,原交易终端8,分期数2,服务人数2,商品编码12,
		//二磁道37,三磁道104,Lrc3,resv20,resv300)
		if(flag == '00')
		{	//00消费: 金额		
			strInput = '12345678'+'12345678'+ flag + Mny +'20120628'+ '123456789012' + '000000';
		}
		else if(flag == '01')
		{	//01撤销 金额，原流水号
			strInput = '12345678'+'12345678'+ flag + Mny +'        '+ '            '+ TraceID
		}
		else if(flag == '02')
		{	//02退货 金额，原交易参考号，原交易日期
			strInput = '12345678'+'12345678'+ flag + Mny + OldDate + OldReference + TraceID;
		}	
		else if(flag == '03')
		{	//03查余 
			strInput = '12345678'+'12345678'+ flag +'            '+'        '+'123456789012'+'000000'
		}
		else if(flag == '04')
		{	//04重打印 原流水号
			strInput = '12345678'+'12345678'+ flag +'            '+'        '+'123456789012'+TraceID;
		}
		else if(flag == '05')
		{	//05签到
			strInput = '12345678'+'12345678'+ flag +'            '+'        '+'123456789012'+'000000';
		}
		else if(flag == '06')
		{	//06结算
			strInput = '12345678'+'12345678'+ flag +'            '+'        '+'123456789012'+'000000';
		}	
		
		var sOrder = $$('txtOrderNo').value;
		//alert('len='+sOrder.length);
		var strRsv = sOrder+Generater(' ', 300-sOrder.length);
		//alert('len='+strRsv.length+',['+strRsv+']');

	 	strInput = strInput
			+'111111222222333333338899555555555555'
			+Generater(' ',37)
			+Generater(' ',104)
			+Generater(' ',3)
			+Generater(' ',20)
			+strRsv;
		
		if(asy==1)
			iRet = ocxobject.BankTransAsyn(strInput);
		else
			iRet = ocxobject.BankTrans(strInput);
			
		$$('S1').value += "\r\n" + iRet + "\r\n";
		
		return false;
	}

	function BankTransAsynCallback(param)
	{
		$$('S1').value += "callback:\r\n" + param + "\r\n";
	}

	function Generater(resvr,len)
	{
		var s = "";
		var i = 0;
		for(; i < len; ++i)
		{
			s = s + resvr;
		}
		return s;
	}

function $$(id) {
	    return !id ? null : document.getElementById(id);
	}
</script>

<script type="text/javascript" language="javascript" for="ocxobject" event="BankTransAsynCallback(param)">
		BankTransAsynCallback(param);
</script>

<body>
<!--clsid : 如果控件成功注册到本机后，这个值在本机注册表中可以找到，js获取控件对象就是通过这个来找的。-->  
<script type="text/javascript">
var _app = navigator.appName;
if (_app == 'Netscape') {
	document.write('<OBJECT name="ocxobject" ID="ocxobject" WIDTH="0" HEIGHT="0"',
			'TYPE="application/x-itst-activex"',
			'clsid="{3C435DB2-0710-4B85-B0CA-6A75CB5D3B17}"',
			'event_BankTransAsynCallback="BankTransAsynCallback"',
			'> </OBJECT>');
			
} else if (_app == 'Microsoft Internet Explorer') {
	document.write('<OBJECT name="ocxobject" ID="ocxobject" WIDTH="0" HEIGHT="0"',
					'CLASSID="CLSID:3C435DB2-0710-4B85-B0CA-6A75CB5D3B17"',
					'> </OBJECT>');
} else {
	document.write('<p>Sorry, unsupported browser.</p>');
} 
</script>
		 <p>	  
		   <textarea  rows="13" name="S1" id="S1" cols="120"  ></textarea>
	     </p>
		  <p>
			<input type="button" value="清空" onclick="clearBtn()" /> 			
		  </p>
		  <p>
				交易类型
				<select id="TranType" >
				<option value="00">消费</option>
				<option value="03">查余</option>
				<option value="02">退货</option>
				<option value="01">撤销</option>
				<option value="05">签到</option>
				<option value="04">重打指定流水</option> 
				<option value="06">结算</option>
				</select>
				</br>
金&nbsp&nbsp额 <input id="txtMny" type="text" MAXLENGTH=12 SIZE=16 value="000000000010"><span>12位金额,分单位</span></br>
原交易日期<input type="text" id="txtOldDate" MAXLENGTH=8 size=13 value="20130101"><span>8位yyyymmdd(退货用)</span></br>
原系统参考号<input type="text" id="txtOldRefSys" MAXLENGTH=12 size=12 value="123456789012"><span>12位(退货用)</span></br> 
流水号 <input type="text" id="txtTraceID" MAXLENGTH=6 size=16 value="123456"><span>6位(撤销、退货、重打用)</span></br>
订单号 <input type="text" id="txtOrderNo" MAXLENGTH=40 size=40 value="20150820111111S001"><span>最多30位</span></br>
		  </p>
		  
		  <p>		      
			<button style="WIDTH: 100px" onclick="test()"> 测试 </button>
			<button style="WIDTH: 100px" onclick="test(1)"> 测试2 </button>
		  </p>
		   
		  
</body>  
</html>  